//用户修改手机页面1
$(function() {

	// 修改绑定的手机号第一步
	$("#nextBtn").click(function() {
		var code = $("#sms").val();// 获取输入的验证码的值
		if (code == "" || code.replace(/(^\s*)|(\s*$)/g, "") == "") {
			$("#codeTipNull").css("display", "block");
		} else {
			$("#codeTipNull").css("display", "none");
			verifyPhoneCode(code);
		}
	});
	function verifyPhoneCode(code) {
		var phoneNumber = $('#phoneSpan').html();
		var data = {
			"code" : code,
			"phoneNumber" : phoneNumber
		}
		console.log(data);
		$("#codeTipNull").css("display", "none");// 验证码为空
		$("#codeTipError").css("display", "none");// 验证码错误
		$
				.ajax({
					type : 'post',
					url : '/tenement/verifyPhoneCode.action',
					data : JSON.stringify(data),
					contentType : "application/json;charset=utf-8",
					success : function(msg) {
						if (msg == "1") {
							window.location = "../../../../../toPersonModifyPhoneHtml2.action";
						} else {
							$("#codeTipError").css("display", "block");
						}
					}
				})
	}

	// 发送验证码倒计时60s
	var countdown = 10;
	var sendPhoneCodeBtn = $("#sendPhoneCodeBtn");
	function settime() {
		if (countdown == 0) {
			sendPhoneCodeBtn.html("获取验证码");
			sendPhoneCodeBtnYes();
			countdown = 10;
			return;
		} else {
			sendPhoneCodeBtn.html("重新发送(" + countdown + ")");
			sendPhoneCodeBtnNo();
			countdown--;
		}
		setTimeout(settime, 1000);
	}
	// 获取验证码按钮可以点击
	function sendPhoneCodeBtnYes() {
		sendPhoneCodeBtn.removeClass("disabled");
		sendPhoneCodeBtn.attr("disabled", false);
	}
	// 获取验证码按钮不可点击
	function sendPhoneCodeBtnNo() {
		sendPhoneCodeBtn.attr("disabled", true);
		sendPhoneCodeBtn.addClass("disabled");
	}

	// 发送手机验证码
	sendPhoneCodeBtn.click(function() {
		settime();
		console.log("【获取手机验证码】");
		var phoneNumber = $('#phoneSpan').html();// 获取输入的验证身份的手机号
		if (phoneNumber != null && phoneNumber != "") {
			$.ajax({
				type : 'post',
				url : '/tenement/sendPhoneCode.action',
				data : phoneNumber,
				contentType : "application/json;charset=utf-8",
				success : function(msg) {
					console.log("【手机验证码发送成功】" + msg);
				},
				error : function(msg) {
					console.log("【系统异常】");
				}
			})
		}
	});
})